#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys

if os.name=='nt':
    BLACK        = 0
    DARK_BLUE    = 1
    DARK_GREEN   = 2
    DARK_CYAN    = 3
    DARK_RED     = 4
    DARK_MAGENTA = 5
    BROWN        = 6
    SILVER       = 7
    GRAY         = 8
    BLUE         = 9
    GREEN        =10
    CYAN         =11
    RED          =12
    MAGENTA      =13
    YELLOW       =14
    WHITE        =15
else:
    BLACK        = 0
    DARK_BLUE    = 4
    DARK_GREEN   = 2
    DARK_CYAN    = 6
    DARK_RED     = 1
    DARK_MAGENTA = 5
    BROWN        = 3
    SILVER       = 7
    GRAY         = 8
    BLUE         =12
    GREEN        =10
    CYAN         =14
    RED          = 9
    MAGENTA      =13
    YELLOW       =11
    WHITE        =15

DefaultFG = SILVER
DefaultBG = BLACK


if os.name=='nt':
   import win32console

   def setcolor(fg=DefaultFG, bg=DefaultBG):
      try:
         stdout=win32console.GetStdHandle(win32console.STD_OUTPUT_HANDLE)
         stdout.SetConsoleTextAttribute((fg&15) + (bg&15)*0x10)
      except:
         pass

   def colorprint(s, fg=DefaultFG, bg=DefaultBG):
      setcolor(fg, bg)
      print str(s)
      setcolor()

   def colorwrite(s, fg=DefaultFG, bg=DefaultBG):
      setcolor(fg, bg)
      sys.stdout.write(str(s))
      setcolor()

else:
   def ascii(fg=DefaultFG, bg=DefaultBG):
      return "\x1B[%d;%d;%dm" % ( ((fg>>3) | (bg>>3)) & 1, 30+(fg&7), 40+(bg&7))

   def setcolor(fg=DefaultFG, bg=DefaultBG):
      sys.stdout.write(ascii(fg, bg))

   def colorprint(s, fg=DefaultFG, bg=DefaultBG):
      print ascii(fg, bg) + str(s) + ascii()

   def colorwrite(s, fg=DefaultFG, bg=DefaultBG):
      sys.stdout.write(ascii(fg, bg) + str(s) + ascii())
      sys.stdout.flush()


if __name__=='__main__':
    colorz = [BLACK,DARK_BLUE,DARK_GREEN,DARK_CYAN,DARK_RED,DARK_MAGENTA,BROWN,SILVER,GRAY,BLUE,GREEN,CYAN,RED,MAGENTA,YELLOW,WHITE]
    for x in colorz:
        for y in colorz:
            colorwrite('%x%x'%(x, y), y, x)
        print
